home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Misc / GMS / GMSDev / Source / C / Blitter / RamboWorm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-12-23  |  4.6 KB  |  195 lines

  1. /* Dice: 1> dcc -l0 -mD dpk.o RamboWorm.c -o RamboWorm
  2. **
  3. ** Blits a Worm to screen using a bob structure.  This version does not
  4. ** include the sound from the assembler version.
  5. */
  6.  
  7. #include <proto/dpkernel.h>
  8.  
  9. BYTE *ProgName      = "Rambo Worm";
  10. BYTE *ProgAuthor    = "Paul Manias";
  11. BYTE *ProgDate      = "December 1997";
  12. BYTE *ProgCopyright = "DreamWorld Productions (c) 1996-1997.  Freely distributable.";
  13. BYTE *ProgShort     = "Bob Demonstration.";
  14.  
  15. struct GScreen  *screen;
  16. struct Restore  *restore;
  17. struct Bob      *Worm;
  18. struct JoyData  *joydata;
  19. struct Picture  *background;
  20. struct FileName BackFile = { ID_FILENAME, "GMS:demos/data/PIC.Green" };
  21. struct FileName bobfile  = { ID_FILENAME, "GMS:demos/data/PIC.Rambo" };
  22.  
  23. WORD WormFrames[] = {
  24.     0,0,  32,0, 64,0,  96,0, 128,0, 160,0, 192,0, 224,0,
  25.   256,0, 288,0, 0,48, 32,48, 64,48,
  26.   -1,-1
  27. };
  28.  
  29. void Demo(void);
  30. void Wrap(struct Bob *);
  31.  
  32. /***************************************************************************/
  33.  
  34. void main(void) {
  35.   if (background = Load(&BackFile, ID_PICTURE)) {
  36.    if (screen = Get(ID_SCREEN)) {
  37.       CopyStructure(background, screen);
  38.       screen->MemPtr1 = background->Bitmap->Data;
  39.       screen->Attrib  = DBLBUFFER;
  40.  
  41.     if (Init(screen,NULL)) {
  42.        CopyBuffer(screen,BUFFER1,BUFFER2);
  43.  
  44.      if (restore = InitTags(screen,
  45.           TAGS_RESTORE, NULL,
  46.           RSA_Entries,  1,
  47.           TAGEND)) {
  48.  
  49.       if (Worm = InitTags(screen,
  50.           TAGS_BOB,      NULL,
  51.           BBA_GfxCoords, WormFrames,
  52.           BBA_Width,     32,
  53.           BBA_Height,    24,
  54.           BBA_XCoord,    150,
  55.           BBA_YCoord,    150,
  56.           BBA_Attrib,    BBF_RESTORE|BBF_GENMASKS|BBF_CLIP,
  57.             BBA_SourceTags, ID_PICTURE,
  58.             PCA_Source,     &bobfile,
  59.               PCA_BitmapTags, NULL,
  60.               BMA_MemType,    MEM_BLIT,
  61.               TAGEND,NULL,
  62.             TAGEND,NULL,
  63.           TAGEND)) {
  64.  
  65.        if (joydata = Init(Get(ID_JOYDATA),NULL)) {
  66.  
  67.           Display(screen); 
  68.           Demo();
  69.  
  70.        }
  71.       }
  72.      }
  73.     }
  74.    }
  75.   Free(joydata);
  76.   Free(Worm);
  77.   Free(restore);
  78.   Free(screen);
  79.   Free(background);
  80.   }
  81. }
  82.  
  83. /***************************************************************************/
  84.  
  85. void Demo(void)
  86. {
  87.   WORD anim = 0;
  88.   WORD fire = FALSE;
  89.   WORD x1,x2,y1,y2,ax1,ax2,ay1,ay2;
  90.  
  91.   do
  92.   {
  93.     Activate(restore); 
  94.     Draw(Worm);
  95.     WaitAVBL();
  96.     SwapBuffers(screen);
  97.  
  98.     /* Animate the Worm's movements */
  99.  
  100.     anim++;
  101.  
  102.     if (fire IS FALSE) {
  103.       if (anim > 5) {
  104.         anim = 0;
  105.         Worm->Frame++;
  106.         if (Worm->Frame > 9)
  107.            Worm->Frame = 0;
  108.       }
  109.     }
  110.     else if (anim > 1) {
  111.       anim = 0;
  112.       if (Worm->Frame < 10)
  113.          Worm->Frame = 9;
  114.  
  115.       Worm->Frame++;
  116.  
  117.       if (Worm->Frame > 12) {
  118.          if (joydata->Buttons & JD_LMB)
  119.             Worm->Frame = 11;
  120.          else {
  121.             Worm->Frame = 0;
  122.             fire = FALSE;
  123.          }
  124.       }
  125.     }
  126.  
  127.     /* Get the user input, wrap the bob around if out of bounds */
  128.  
  129.     Query(joydata);
  130.     Worm->XCoord += joydata->XChange;
  131.     Worm->YCoord += joydata->YChange;
  132.     Wrap(Worm);
  133.  
  134.     if (joydata->Buttons & JD_LMB) {
  135.        fire = TRUE;
  136.     }
  137.  
  138.   } while (!(joydata->Buttons & JD_RMB));
  139.  
  140.  
  141.   /* Randomly perform a screen wipe effect before
  142.   ** exiting the demo.
  143.   */
  144.  
  145.   if (FastRandom(5) IS 4) {
  146.      ax1 = x1 = (screen->Width - screen->Height)/2;
  147.      ay1 = y1 = NULL;
  148.  
  149.      ax2 = x2 = screen->Width - ((screen->Width - screen->Height)/2);
  150.      ay2 = y2 = screen->Height;
  151.  
  152.      while (x1 < screen->Width) {
  153.         DrawLine(screen->Bitmap,x1,y1,x2,y2,0);
  154.         DrawLine(screen->Bitmap,ax1,ay1,ax2,ay2,0);
  155.         DrawLine(screen->Bitmap,x1+1,y1,x2+1,y2,0);
  156.         DrawLine(screen->Bitmap,ax1+1,ay1,ax2+1,ay2,0);
  157.         WaitAVBL();
  158.         SwapBuffers(screen);
  159.  
  160.         DrawLine(screen->Bitmap,x1,y1,x2,y2,0);
  161.         DrawLine(screen->Bitmap,ax1,ay1,ax2,ay2,0);
  162.         DrawLine(screen->Bitmap,x1+1,y1,x2+1,y2,0);
  163.         DrawLine(screen->Bitmap,ax1+1,ay1,ax2+1,ay2,0);
  164.         WaitAVBL();
  165.         SwapBuffers(screen);
  166.  
  167.         x1  += 2;  x2 += 2;
  168.         ax1 -= 2; ax2 -= 2;
  169.      }
  170.   }
  171. }
  172.  
  173. /*****************************************************************************
  174. ** Function: This function will wrap a bob to the other side of a screen if
  175. **           it leaves the bob's screen borders.
  176. **
  177. ** Synopsis: Wrap(Bob);
  178. */
  179.  
  180. void Wrap(struct Bob *bob)
  181. {
  182.   if (bob->XCoord < -bob->Width)
  183.      bob->XCoord = bob->DestBitmap->Width;
  184.  
  185.   if (bob->XCoord > bob->DestBitmap->Width)
  186.      bob->XCoord = -bob->Width;
  187.  
  188.   if (bob->YCoord < -bob->Height)
  189.      bob->YCoord = bob->DestBitmap->Height;
  190.  
  191.   if (bob->YCoord > bob->DestBitmap->Height)
  192.      bob->YCoord = -bob->Height;
  193. }
  194.  
  195.